package com.carrental.vehicle.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carrental.common.result.Result;
import com.carrental.vehicle.entity.VehicleBrand;
import com.carrental.vehicle.service.VehicleBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆品牌控制器
 */
@Api(tags = "车辆品牌管理")
@RestController
@RequestMapping("/vehicle-brands")
@RequiredArgsConstructor
public class VehicleBrandController {

    private final VehicleBrandService vehicleBrandService;

    @ApiOperation("根据ID获取品牌")
    @GetMapping("/{id}")
    public Result<VehicleBrand> getBrandById(
            @ApiParam("品牌ID") @PathVariable Long id) {
        return Result.success(vehicleBrandService.getBrandById(id));
    }

    @ApiOperation("保存或更新品牌")
    @PostMapping("/save")
    public Result<Boolean> saveOrUpdateBrand(
            @ApiParam("品牌信息") @Validated @RequestBody VehicleBrand vehicleBrand) {
        return Result.success(vehicleBrandService.saveOrUpdateBrand(vehicleBrand));
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteBrandById(
            @ApiParam("品牌ID") @PathVariable Long id) {
        return Result.success(vehicleBrandService.deleteBrandById(id));
    }

    @ApiOperation("分页查询品牌")
    @GetMapping("/page")
    public Result<Page<VehicleBrand>> pageBrand(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("品牌名称") @RequestParam(required = false) String name,
            @ApiParam("国家") @RequestParam(required = false) String country) {
        Page<VehicleBrand> page = new Page<>(current, size);
        VehicleBrand brand = new VehicleBrand();
        brand.setName(name);
        brand.setCountry(country);
        return Result.success(vehicleBrandService.pageBrand(page, brand));
    }

    @ApiOperation("获取所有品牌")
    @GetMapping("/list")
    public Result<List<VehicleBrand>> listAllBrands() {
        return Result.success(vehicleBrandService.listAllBrands());
    }

    @ApiOperation("获取所有可用的品牌")
    @GetMapping("/list/available")
    public Result<List<VehicleBrand>> listAvailableBrands() {
        return Result.success(vehicleBrandService.listAvailableBrands());
    }
} 